package com.ftg.learn.course.controller;

import com.ftg.learn.course.dto.QueryDto;
import com.ftg.learn.course.entity.Course;
import com.ftg.learn.course.result.PageResult;
import com.ftg.learn.course.result.Result;
import com.ftg.learn.course.service.CourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/course")
@Tag(name = "课程管理模块")
@AllArgsConstructor
public class CourseController {
    @Autowired
    private final CourseService courseService;

    @GetMapping("/getAll")
    @Operation(summary = "获取所有课程")
    public Result<PageResult> getPage(@RequestBody  QueryDto queryDto){
        return courseService.getPage(queryDto);
    }
    @GetMapping
    @Operation(summary = "获取课程")
    public Result<Course> getOne(Long id){
        log.info("课程模块被调用");
        return courseService.MygetOne(id);
    }
    @PostMapping
    @Operation(summary = "添加课程")
    public Result<String> add(@RequestBody Course course){
        return courseService.add(course);
    }
    @PutMapping
    @Operation(summary = "修改课程")
    public Result<String> update(@RequestBody Course course){
        return courseService.myupdate(course);
    }

}
